package zhr.chapter9;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class MyDialog extends JFrame implements ActionListener {
    static final int YES =1,NO=0;
    int message=-1;
    JButton yes,no;
    MyDialog(JFrame f,String s,boolean b) {
        super();
        yes=new JButton("Yes");
        no=new JButton("No");
        yes.addActionListener(this);
        no.addActionListener(this);
        setLayout(new FlowLayout());
        add(yes);
        add(no);
        setBounds(60,60,100,100);
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                message= -1;
                setVisible(false);
            }
        });
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getSource()==yes) {
            message=YES;
            setVisible(false);
        }else if(e.getSource()==no) {
            message=NO;
            setVisible(false);
        }
    }
    public int getMessage(){
        return message;
    }
}
